package com.mmall.controller.portal;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.mmall.common.Const;
import com.mmall.common.RedisPool;
import com.mmall.common.ServerResponse;
import com.mmall.pojo.User;
import com.mmall.service.IUserService;
import com.mmall.util.JsonUtil;
import com.mmall.util.RedisPoolUtil;

@Controller
@RequestMapping("/user/")
public class UserController {

	@Autowired
	private IUserService iUserService;

	@RequestMapping(value = "login.do", method = RequestMethod.GET)
	@ResponseBody
	public ServerResponse<User> login(String username, String password, HttpSession session,
			HttpServletResponse httpServletResponse) {
		ServerResponse<User> response = iUserService.login(username, password);
		if (response.isSuccess()) {
//			session.setAttribute(Const.CURRENT_USER, response.getData());
			RedisPoolUtil.setEx(session.getId(),JsonUtil.obj2String(response) , Const.RedisCacheExtime.REDIS_SESSION_EXTIME);
		}
		return response;
	}

}
